package com.jumi.microservice.controller.logistics.admin;

import com.alibaba.excel.EasyExcel;
import com.jumi.microservice.common.base.BaseController;
import com.jumi.microservice.common.base.dto.ExportExcelCommonResponse;
import com.jumi.microservice.common.base.dto.ResponseResult;
import com.jumi.microservice.domain.ExpressDataDTO;
import com.jumi.microservice.dto.finance.*;
import com.jumi.microservice.dto.finance.excel.GoodsDetailExcel;
import com.jumi.microservice.dto.logistics.admin.EditOrPartSendRequest;
import com.jumi.microservice.dto.logistics.admin.SelfWaitSendRequest;
import com.jumi.microservice.dto.logistics.excel.SelfWaitSend;
import com.jumi.microservice.service.finance.GoodsSaleDetailService;
import com.jumi.microservice.service.logistics.admin.SendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * @author by mazhao
 * @Classname EditSendController
 * @Description TODO
 * @Date 2020/8/24 11:12
 */
@RestController
@RequestMapping("/admin/finance/")
@Api(tags = {"财务商品销售明细接口"})
public class FinanceController extends BaseController {

    @Resource
    GoodsSaleDetailService goodsSaleDetailService;

    @ApiOperation("商品销售明细")
    @PostMapping("/goodsSaleDetail")
    public ResponseResult<GoodsSaleDetailResponse> cancelLogistics(GoodsSaleDetailRequest request){
        return success(goodsSaleDetailService.list(request));
    }

    @ApiOperation("商品状态字典")
    @GetMapping("/goodsStatus")
    public ResponseResult<List<GoodsStatusResponse>> goodsStatus(){
        return success(goodsSaleDetailService.goodsStatus());
    }

    @ApiOperation("商品销售明细导出")
    @PostMapping("/export")
    public void excelExport(HttpServletResponse response, GoodsSaleDetailRequest request) throws IOException {
        ExportExcelCommonResponse<GoodsDetailExcel> excelExportExportExcelCommonResponse = goodsSaleDetailService.excelExport(request);
        response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel");
        response.setCharacterEncoding("utf-8");
        response.setHeader("Content-disposition", "attachment;filename="+ excelExportExportExcelCommonResponse.getFileName());
        EasyExcel.write(response.getOutputStream(),GoodsDetailExcel.class).sheet("sheet1").doWrite(excelExportExportExcelCommonResponse.getData());
    }

    @ApiOperation("获取收益用户列表")
    @PostMapping("/userList")
    public ResponseResult<List<UserInfo>> userList(UserListRequest request){
        return success(goodsSaleDetailService.getUserList(request));
    }


}
